package com.systop.ltbook.favorite.service;

import java.util.List;

import org.springframework.stereotype.Service;

import com.systop.common.modules.security.user.model.User;
import com.systop.core.service.BaseGenericsManager;
import com.systop.ltbook.book.model.Book;
import com.systop.ltbook.favorite.model.Favorite;

/**
 * 我的收藏管理类
 * @author DU
 *
 */
@Service
public class FavoriteManager extends BaseGenericsManager<Favorite> {

	/**
	 * 判断用户是否已经收藏了该图书
	 * @param logUser 用户
	 * @param book 图书
	 */
	@SuppressWarnings("unchecked")
  public boolean isAddFavorite(User logUser, Book book) {
		boolean added = false;
		String hql = "from Favorite fv where fv.owner.id = ? and fv.book.id = ?";
		if (logUser != null && book != null) {
			List list = getDao().query(hql, logUser.getId(), book.getId());
			if (list != null && list.size() > 0) {
				added = true;
			}
		}
		
		return added;
	}
}
